home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1993 March / Nautilus-4-3 / Nautilus-4-3.bin / Multimedia / Feature / Image 1.47 Folder / Macros / More Macros < prev    next >
Encoding:
Text File  |  1992-10-15  |  9.2 KB  |  440 lines

  1. macro 'Fix Pseudocolors';
  2. begin
  3.   ChangeValues(0,0,1);
  4.   ChangeValue(255,255,254);
  5. end;
  6.  
  7.  
  8. macro 'Invert Image';
  9. {
  10. This macro illustrates why it's not a good idea to use
  11. macros to do pixel-by-pixel processing.
  12. }
  13. var
  14.   width,height,value,x,y:integer;
  15. begin
  16.   RequiredVersion(1.44);
  17.   GetPicSize(width,height);
  18.   for y:=0 to height-1 do begin
  19.     GetRow(0,y,width);
  20.     for x:=0 to width-1 do LineBuffer[x]:=255-LineBuffer[x];
  21.     PutRow(0,y,width);
  22.   end;
  23. end;
  24.  
  25.  
  26. macro 'Remove Isolated Black Lines';
  27. var
  28.   width,height,value,x,y,xstart,ystart:integer;
  29. begin
  30.   GetRoi(xstart,ystart,width,height);
  31.   if width=0 then begin
  32.     PutMessage('This macro requires a retangular selection');
  33.     exit;
  34.   end;
  35.   for y:=ystart to ystart+height-1 do begin
  36.     if GetPixel(width div 2,y)=255 then
  37.       for x:=xstart to xstart+width-1 do
  38.         PutPixel(x,y,(GetPixel(x,y-1)+GetPixel(x,y+1))/2);
  39.   end;
  40.   KillRoi;
  41. end;
  42.  
  43.  
  44. macro 'Make Mosaic';
  45. var
  46.   n:integer;
  47. begin
  48.   SaveState
  49.   n:=GetNumber('Cell Size(pixels square):',8);
  50.   Duplicate('Mosaic');
  51.   SetScaling('Nearest; Same Window');
  52.   ScaleSelection(1/n,1/n);
  53.   RestoreRoi;
  54.   ScaleSelection(n,n);
  55.   RestoreState;
  56. end;
  57.  
  58.  
  59. macro 'Draw Vertical Scale with Labels';
  60. var
  61.   left,top,width,height,i,x,y2,inc:integer;
  62.   y:real;
  63. begin
  64.   GetRoi(left,top,width,height);
  65.   if width=0 then begin
  66.     PutMessage('Make a selection first.');
  67.     exit;
  68.   end;
  69.   SetFont('Helvetica');
  70.   SetFontSize(10);
  71.   SetText('Plain; Left; no background');
  72.   SetLineWidth(1);
  73.   Setforeground(255);
  74.   DrawScale;
  75.   x:=left;
  76.   y:=top;
  77.   inc:=height/10;
  78.   for i:=1 to 11 do begin
  79.     MoveTo(x+width+10,round(y)+2);
  80.     y2:=round(y);
  81.     if i=11 then y2:=y2-1;
  82.     write(cvalue(GetPixel(x,y2)):1:2);
  83.     y:=y+inc;
  84.   end;
  85. end;
  86.  
  87.  
  88. macro 'Speckle Paint [S]';
  89. var
  90.   x,y,ranx,rany,MaxSpeckSize,size,Spread:integer;
  91. begin
  92.   {SaveState;}
  93.   Spread:=50;
  94.   MaxSpeckSize:=5;
  95.   KillRoi;
  96.   repeat
  97.     GetMouse(x,y);
  98.     if button then begin
  99.       ranx:=x+Spread*(Random-0.5);
  100.       rany:=y+Spread*(Random-0.5);
  101.       size:=(MaxSpeckSize-2)*random+2;
  102.       MakeOvalRoi(ranx-size,rany-size,size*2,size*2);
  103.       SetForeground(Random*254+1)
  104.       fill;
  105.     end;
  106.   until (x<0) or (y<0);
  107.   KillRoi;
  108.   {RestoreState;}
  109. end;
  110.  
  111.  
  112. macro 'Draw Histogram';
  113. var
  114.   max,scale:real;
  115.   i,margin,width,height:integer;
  116. begin
  117.   SaveState;
  118.   Margin:=10;
  119.   width:=256;
  120.   height:=0.6*256;
  121.   Measure;
  122.   SetForegroundColor(255);
  123.   SetBackgroundColor(0);
  124.   SetLineWidth(1);
  125.   SetNewSize(width+2*margin,height+2*margin);
  126.   MakeNewWindow('Histogram');
  127.   MakeRoi(margin,margin-1,width,height+1);
  128.   DrawBoundary;
  129.   max:=0;
  130.   for i:=1 to 254 do
  131.   if histogram[i]> max then max:=histogram[i];
  132.   scale:=height/max;
  133.   for i:=1 to 254 do begin
  134.     MakeRoi(margin+i,margin,1,histogram[i]*scale);
  135.     SetForegroundColor(i);
  136.     fill;
  137.  end;
  138.   SelectAll;
  139.   FlipVertical;
  140.   KillRoi;
  141.   RestoreState;
  142. end;
  143.  
  144.  
  145. macro 'Subtract Background [B]';
  146. var
  147.   i,Corrected,smoothf:integer;
  148.   scalef:real;
  149. begin
  150.   scalef:=.125;
  151.   smoothf:=10;
  152.   SelectAll;
  153.   Duplicate('Background Corrected');
  154.   Corrected:=PicNumber;
  155.   Duplicate('Background');
  156.   SetScaling('Bilinear'); 
  157.   ScaleSelection(scalef,scalef);
  158.   RestoreRoi;
  159.   for i:=1 to smoothf do begin
  160.     SetOption; Smooth;
  161.   end;
  162.   ScaleSelection(1/scalef,1/scalef);
  163.   ScaleMath(false);
  164.   SelectAll;
  165.   Copy;
  166.   SelectPic(Corrected);
  167.   Paste;
  168.   Subtract;
  169.   ResetGrayMap;
  170. end;
  171.  
  172.  
  173. macro 'ASCII Dump';
  174. {
  175. Generates an alphanumeric listing of pixels values starting at
  176. the upper left corner of the current selection. 20 rows and 44 columns
  177. can be displayed with the default 552 x 436 window. The size of the window
  178. used to display the pixel values is determined by New Width and
  179. New Height in the Prefernces dialog box.
  180. }
  181. var
  182.   image,dump,roiLeft,roiTop,roiWidth,roiHeight:integer;
  183.   h,v,value,MaxWidth,MaxHeight,width,height:integer;
  184. begin
  185.   image:=PicNumber;
  186.   GetRoi(RoiLeft,RoiTop,RoiWidth,RoiHeight);
  187.   if roiWidth=0 then begin
  188.     PutMessage('This macro requires a rectangular selection');
  189.     exit;
  190.   end;
  191.   SetForegroundColor(255);
  192.   SetBackgroundColor(0);
  193.   MakeNewWindow('ASCII Dump');
  194.   dump:=PicNumber;
  195.   GetPicSize(width,height);
  196.   MaxWidth:=width div 24 - 2;
  197.   MaxHeight:=height div 9 - 3;
  198.   if roiWidth>MaxWidth then roiWidth:=MaxWidth;
  199.   if roiHeight>MaxHeight then roiHeight:=MaxHeight;
  200.   SetFont('Monaco');
  201.   SetFontSize(9);
  202.   SetText('No background; Left Justified');
  203.   MoveTo(2,12);
  204.   write('    ');
  205.   for h:=roiLeft to roiLeft+roiWidth-1 do write(h:4);
  206.   writeln;
  207.   writeln;
  208.   for v:=roiTop to roiTop+roiHeight-1 do begin
  209.     write(v:3,' ');
  210.     for h:=roiLeft to roiLeft+roiWidth-1 do begin
  211.       ChoosePic(image);
  212.       value:=GetPixel(h,v);
  213.       ChoosePic(dump);
  214.       write(value:4);
  215.     end;
  216.     writeln;
  217.   end;
  218.   ChoosePic(image);
  219. end;
  220.  
  221.  
  222. macro 'Resize All';
  223. {
  224. Resizes and/or rotates all currently open widows. For example,
  225. change the  ScaleAndRotate command below to
  226. ScaleAndRotate(2,2,0)  to change the size of all the images
  227. in a movie loop sequence from 128 x 128 to 256 x 256.
  228. }
  229. var
  230.   i:integer;
  231. begin
  232.   SaveState;
  233.   SetScaling('Bilinear; Create New Window');
  234.   for i:=1 to nPics do begin
  235.     ChoosePic(1);
  236.     ScaleAndRotate(1.9,1.9,0);
  237.     ChoosePic(1);
  238.     Close;
  239.   end;
  240.   for i:=1 to nPics do begin
  241.     ChoosePic(i);
  242.     SetPicName(i);
  243.   end;
  244.   RestoreState;
  245. end;
  246.  
  247.  
  248. macro 'Dispose All';
  249. begin
  250.   DisposeAll;
  251. end;
  252.  
  253. macro 'Average two Images';
  254.   {Generates the arithmetic average of two images.}
  255. begin
  256.   if nPics<>2 then begin
  257.     PutMessage('This macro requires exactly two image windows to be open.');
  258.     Exit;
  259.   End;
  260.   ScaleMath(false);
  261.   MultiplyByConstant(0.5);
  262.   NextWindow;
  263.   MultiplyByConstant(0.5);
  264.   SelectAll;
  265.   Copy;
  266.   NextWindow;
  267.   Paste;
  268.   Add;
  269. end;
  270.  
  271.  
  272. macro 'Make Montage [M]';
  273. {Opens a new window and creates in it a composite image made from all}
  274. {currently open images. All the images must be the same size.}
  275. var
  276.   width,height,w,h,mWidth,mHeight,nWindows,left,top:integer;
  277.   RoiWidth,RoiHeight,RoiWidth,RoiHeight,i,hloc,vloc:integer;
  278.   montage,temp:integer;
  279.   scale:real;
  280.   SameSize:boolean;
  281. begin
  282.   nWindows:=nPics;
  283.   SameSize:=true;
  284.   GetPicSize(width,height);
  285.   for i:=1 to nPics do begin
  286.     SelectPic(i);
  287.     GetPicSize(w,h);
  288.     SameSize:=SameSize and (w=width) and (h=height);
  289.   end;
  290.   if (nWindows<2) or not SameSize then begin
  291.     PutMessage('This macro needs two or more images of the same size in order to create a montage.');
  292.     Exit;
  293.   end;
  294.   SetBackground(0);
  295.   MakeNewWindow('Montage');
  296.   montage:=nWindows+1;
  297.   GetPicSize(mWidth,mHeight);
  298.   SelectPic(1);
  299.   Duplicate('Temp');
  300.   temp:=nWindows+2;
  301.   scale:=GetNumber('Scaling Factor:',0.25);
  302.   hloc:=-(RoiWidth);
  303.   vloc:=0;
  304.   for i:=1 to nWindows do begin
  305.     SelectPic(i);
  306.     SelectAll;
  307.     copy;
  308.     SelectPic(temp);
  309.     paste;
  310.     SelectAll;
  311.     ScaleSelection(scale,scale);
  312.     RestoreRoi;
  313.     if i=1 then begin
  314.       GetRoi(left,top,RoiWidth,RoiHeight);
  315.       hloc:=-RoiWidth;
  316.       vloc:=0;
  317.     end;
  318.     Copy;
  319.     SelectPic(montage);
  320.     hloc:=hloc+RoiWidth;
  321.     if (hloc+RoiWidth)>mWidth then begin
  322.       hloc:=0;
  323.       vloc:=vloc+RoiHeight;
  324.     end;
  325.     MakeRoi(hloc,vloc,RoiWidth,RoiHeight);
  326.     Paste;
  327.   end;
  328.   KillRoi;
  329.   SelectPic(temp);
  330.   Dispose;
  331. end;
  332.  
  333.  
  334. macro 'Make Sine Wave';
  335. var
  336.   left,top,width,height,i:integer;
  337.   ppp,scale:real;
  338. begin
  339.   SaveState;
  340.   MakeNewWindow('Sine Wave');
  341.   SelectAll;
  342.   GetRoi(left,top,Width,Height);
  343.   if width=0 then begin
  344.     PutMessage('This macro requires a rectangular selection.');
  345.     Exit;
  346.   end;
  347.   ppp:=GetNumber('Pixels per period',100);
  348.   Scale:=ppp/6.28;
  349.   MakeRoi(left,top,1,height);
  350.   for i:=1 to width do begin
  351.     SetForeground(sin(i/scale)*127 +128);
  352.     {SetForeground((sin(i/scale)*127 +128)*(i+30)/(width));}
  353.     {SetForeground(sin(i/(ppp*((width-i+3)/width)/6.28))*127 +128);}
  354.     fill;
  355.     MoveRoi(1,0);
  356.   end;
  357.   KillRoi;
  358.   RestoreState;
  359. end;`
  360.  
  361.  
  362. macro 'Grid';
  363. var
  364.   n,PicWidth,PicHeight,hloc,vloc,size:integer;
  365. begin
  366.   SaveState;
  367.   n:=24;
  368.   GetPicSize(PicWidth,PicHeight);
  369.   if PicWidth=0 then begin
  370.     PutMessage
  371.     ('This macro needs an opened image, preferably in color, to operate on.');
  372.     Exit;
  373.   end;
  374.   size:=round(PicWidth/n);
  375.   repeat
  376.     hloc:=((PicWidth*random) div size)*size;
  377.     vloc:=((PicHeight*random) div size)*size;
  378.     MakeRoi(hloc,vloc,size,size);
  379.     SetForeground(255*random);
  380.     fill;
  381.     {Invert;}
  382.   until Button;
  383.   KillRoi;
  384.   RestoreState;
  385. end;
  386.  
  387.  
  388. macro 'Plot XYZ';
  389. {
  390. Plots X-Y coordinate points with an optional intensity(Z). Values are read from
  391. a 2 or 3 column tab-delimited text file. Data must be scaled as follows:
  392. 0<=X<width; 0<=Y<height; 0<=Z<=255.
  393. }
  394. var
  395.   width,height:integer;
  396. begin
  397.   SaveState;
  398.   width:=500;
  399.   height:=500;
  400.   SetNewSize(width,height);
  401.   SetForeground(255);
  402.   SetBackground(0);
  403.   MakeNewWindow('Plot');
  404.   PlotXYZ;
  405.   RestoreState;
  406. end;
  407.  
  408.  
  409. macro '(---'; begin end;
  410.  
  411. macro '5x5 [5]';
  412. {
  413. Note: you only see the open file dialog box the first time one of
  414. these macros is called, since Image keeps track of the folder
  415. containing the convolution kernels.
  416. }
  417. begin
  418.   convolve('Hat(5x5)');
  419. end;
  420.  
  421. macro '7x7  [7]'
  422. begin
  423.   convolve('Hat(7x7)');
  424. end;
  425.  
  426. macro '9x9  [9]'
  427. begin
  428.   convolve('Hat(9x9)');
  429. end;
  430.  
  431.  
  432. macro '(---'; begin end;
  433.  
  434. {These macros allow you to easily switch}
  435. {transfer modes while pasting by tapping keys.}
  436. macro 'Copy Mode[F1]'; begin SetOption; DoCopy; end;
  437. macro 'AND Mode[F2]';  begin SetOption; DoAnd; end;
  438. macro 'OR Mode [F3]';  begin SetOption; DoOr; end;
  439.  
  440.